package com.itcam.cli.example;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
// some exports omitted for the sake of brevity

/**
 * 这是一个命令行工具，用于生成 ASCII 艺术图形。
 * 它使用 picocli 库来处理命令行参数和选项。
 */
@Command(name = "ASCIIArt", version = "ASCIIArt 1.0", mixinStandardHelpOptions = true)
public class ASCIIArt implements Runnable {

    /**
     * 字体大小选项，默认值为 19。
     */
    @Option(names = {"-s", "--font-size"}, description = "Font size")
    int fontSize = 19;

    /**
     * 要转换为 ASCII 艺术的单词参数，默认值为 "Hello, picocli"。
     */
    @Parameters(paramLabel = "<word>", defaultValue = "Hello, picocli",
            description = "Words to be translated into ASCII art.")
    private String[] words = {"Hello,", "picocli"};

    /**
     * 命令的主要执行逻辑。
     * 在这里，我们将生成 ASCII 艺术图形的代码。
     * （为了简洁起见，省略了具体实现）
     */
    @Override
    public void run() {
        // 自己实现业务逻辑
        System.out.println("fontSize = " + fontSize);
        System.out.println("words = " + String.join(",", words));
    }

    /**
     * 程序的入口点。
     * 创建一个 CommandLine 实例并执行命令。
     *
     * @param args 命令行参数
     */
    public static void main(String[] args) {
        // 创建一个 CommandLine 实例并执行命令
        int exitCode = new CommandLine(new ASCIIArt()).execute("--help");
        // 退出程序
        System.exit(exitCode);
    }
}

/**
 * Let’s break it down into small steps:
 *
 * Create a class that implements Runnable or Callable. This is your command.
 * Annotate the class with @Command and give it a name. The mixinStandardHelpOptions attribute adds --help and --version options to your application.
 * For each option in your application, add an @Option-annotated field to your command class. This example shows how you can give the options names and a description, there are many other attributes.
 * For each positional parameter, add a @Parameters-annotated field to your command class.
 * Picocli will convert the command line arguments to strongly typed values and will inject these values into the annotated fields.
 * Define your business logic in the run or call method of your class. This method is called after parsing is successfully completed.
 * In the main method of your class, use the CommandLine.execute method bootstrap your application. This will parse the command line, handle errors, handle requests for usage and version help, and invoke the business logic.
 * The CommandLine.execute method returns an exit code. Your application can call System.exit with this exit code to signal success or failure to the calling process.
 */
